class Solution {
public:
    string trans(string s, int n)
    {
        if (n == 0)
            return s;
        for (int i = 0; i < n; i++)
        {
            if (s[i] <= 'Z' && s[i] >= 'A')
                s[i] += 32;
            else if (s[i] >= 'a' && s[i] <= 'z')
                s[i] -= 32;
        }
        reverse(s.begin(), s.end());
        for (int i = 0; i < n; i++)
        {
            int j = i;
            while (j < n && s[j] != ' ')
            {
                j++;
            }
            reverse(s.begin() + i, s.begin() + j);
            i = j;
        }
        return s;
    }
};